package com.htc.android.footprints.view;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.htc.android.footprints.vo.Footprint;

public class GpsUpdatePanel extends LinearLayout
{
  private static final long DELAY_TIME_LONG = 5000L;
  private static final long DELAY_TIME_SHORT = 2000L;
  private static final int HANDLE_INPUT_CHECK = 10;
  private static final String TAG = "GpsUpdatePanel";
  private View.OnClickListener doUpdate = new View.OnClickListener()
  {
    public void onClick(View paramView)
    {
      if (GpsUpdatePanel.this.mCallback != null)
        GpsUpdatePanel.this.mCallback.onTracking();
    }
  };
  private boolean gpsEnabled = true;
  private boolean isIgnoreEditChange = false;
  private PanelCallback mCallback = null;
  private EditText mDegE = null;
  private EditText mDegN = null;
  private Footprint mFootprint = null;
  private Button mGpsE = null;
  private Button mGpsN = null;
  private final Handler mHandler = new Handler()
  {
    public void handleMessage(Message paramMessage)
    {
      switch (paramMessage.what)
      {
      default:
      case 10:
      }
      while (true)
      {
        return;
        Log.i("GpsUpdatePanel", "HANDLE_INPUT_CHECK");
        GpsUpdatePanel.this.checkEditText();
        GpsUpdatePanel.this.updateLocationFromEdit(false);
        if (GpsUpdatePanel.this.mCallback == null)
          continue;
        GpsUpdatePanel.this.mCallback.onUpdatMap();
      }
    }
  };
  private EditText mMinE = null;
  private EditText mMinN = null;
  private EditText mSecE1 = null;
  private EditText mSecE2 = null;
  private EditText mSecN1 = null;
  private EditText mSecN2 = null;
  private long mTimeStamp = 0L;
  private View.OnClickListener showAlert = new View.OnClickListener()
  {
    public void onClick(View paramView)
    {
      new HtcAlertDialog.Builder(GpsUpdatePanel.this.mContext).setTitle(GpsUpdatePanel.this.mContext.getResources().getString(2131361812)).setIcon(17301543).setMessage(GpsUpdatePanel.this.mContext.getResources().getString(2131361941)).setPositiveButton(2131361949, new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramDialogInterface, int paramInt)
        {
          GpsUpdatePanel.access$402(GpsUpdatePanel.this, true);
          Intent localIntent = new Intent("android.settings.LOCATION_SOURCE_SETTINGS");
          paramDialogInterface.dismiss();
          GpsUpdatePanel.this.mContext.startActivity(localIntent);
        }
      }).setNegativeButton(2131361796, new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramDialogInterface, int paramInt)
        {
          paramDialogInterface.dismiss();
        }
      }).show();
    }
  };
  TextWatcher textWatcher = new TextWatcher()
  {
    public void afterTextChanged(Editable paramEditable)
    {
      if (GpsUpdatePanel.this.isIgnoreEditChange)
        GpsUpdatePanel.this.mHandler.removeMessages(10);
      while (true)
      {
        return;
        if (GpsUpdatePanel.this.mHandler.hasMessages(10))
          GpsUpdatePanel.this.mHandler.removeMessages(10);
        GpsUpdatePanel.this.mHandler.sendEmptyMessageDelayed(10, 5000L);
      }
    }

    public void beforeTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3)
    {
    }

    public void onTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3)
    {
    }
  };
  private ImageView updateButton;
  private boolean updateRequired = false;

  public GpsUpdatePanel(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    initView();
  }

  public GpsUpdatePanel(Context paramContext, boolean paramBoolean)
  {
    super(paramContext);
    initView();
  }

  private boolean checkEditText()
  {
    boolean bool = true;
    checkEmpty();
    int i = Integer.parseInt(this.mDegN.getText().toString());
    int j = Integer.parseInt(this.mMinN.getText().toString());
    int k = Integer.parseInt(this.mSecN1.getText().toString());
    int m = Integer.parseInt(this.mSecN2.getText().toString());
    if (i > 89)
    {
      this.mDegN.setText("89");
      bool = false;
    }
    if (j > 59)
    {
      this.mMinN.setText("59");
      bool = false;
    }
    if (k > 59)
    {
      this.mSecN1.setText("59");
      this.mSecN2.setText("00");
      bool = false;
    }
    if ((k == 59) && (m != 0))
    {
      this.mSecN2.setText("00");
      bool = false;
    }
    int n = Integer.parseInt(this.mDegE.getText().toString());
    int i1 = Integer.parseInt(this.mMinE.getText().toString());
    int i2 = Integer.parseInt(this.mSecE1.getText().toString());
    int i3 = Integer.parseInt(this.mSecE2.getText().toString());
    if (n > 179)
    {
      this.mDegE.setText("179");
      bool = false;
    }
    if (i1 > 59)
    {
      this.mMinE.setText("59");
      bool = false;
    }
    if (i2 > 59)
    {
      this.mSecE1.setText("59");
      this.mSecE2.setText("00");
      bool = false;
    }
    if ((i2 == 59) && (i3 != 0))
    {
      this.mSecE2.setText("00");
      bool = false;
    }
    invalidate();
    Log.d("GpsUpdatePanel", "checkEditText = " + bool);
    return bool;
  }

  private void checkEmpty()
  {
    if (this.mDegN.getText().length() == 0)
      this.mDegN.setText("0");
    if (this.mMinN.getText().length() == 0)
      this.mMinN.setText("0");
    if (this.mSecN1.getText().length() == 0)
      this.mSecN1.setText("0");
    if (this.mSecN2.getText().length() == 0)
      this.mSecN2.setText("0");
    if (this.mDegE.getText().length() == 0)
      this.mDegE.setText("0");
    if (this.mMinE.getText().length() == 0)
      this.mMinE.setText("0");
    if (this.mSecE1.getText().length() == 0)
      this.mSecE1.setText("0");
    if (this.mSecE2.getText().length() == 0)
      this.mSecE2.setText("0");
  }

  private void checkLatitudeLongitude()
  {
    if (this.mFootprint != null)
    {
      if (this.mFootprint.mLatitude >= 0)
        break label46;
      this.mGpsN.setText(2131361805);
      if (this.mFootprint.mLongitude >= 0)
        break label58;
      this.mGpsE.setText(2131361806);
    }
    while (true)
    {
      return;
      label46: this.mGpsN.setText(2131361803);
      break;
      label58: this.mGpsE.setText(2131361804);
    }
  }

  private void reset()
  {
    this.mDegN.setText("00");
    this.mMinN.setText("00");
    this.mSecN1.setText("00");
    this.mSecN2.setText("00");
    this.mDegE.setText("00");
    this.mMinE.setText("00");
    this.mSecE1.setText("00");
    this.mSecE2.setText("00");
    if (this.mFootprint != null)
    {
      this.mFootprint.mLatitude = 0;
      this.mFootprint.mLongitude = 0;
    }
  }

  private void setTextWatcher()
  {
    this.mDegN.addTextChangedListener(this.textWatcher);
    this.mMinN.addTextChangedListener(this.textWatcher);
    this.mSecN1.addTextChangedListener(this.textWatcher);
    this.mSecN2.addTextChangedListener(this.textWatcher);
    this.mDegE.addTextChangedListener(this.textWatcher);
    this.mMinE.addTextChangedListener(this.textWatcher);
    this.mSecE1.addTextChangedListener(this.textWatcher);
    this.mSecE2.addTextChangedListener(this.textWatcher);
  }

  private void switchEditable(boolean paramBoolean)
  {
    this.mDegN.setEnabled(paramBoolean);
    this.mMinN.setEnabled(paramBoolean);
    this.mSecN1.setEnabled(paramBoolean);
    this.mSecN2.setEnabled(paramBoolean);
    this.mDegE.setEnabled(paramBoolean);
    this.mMinE.setEnabled(paramBoolean);
    this.mSecE1.setEnabled(paramBoolean);
    this.mSecE2.setEnabled(paramBoolean);
    this.mGpsN.setEnabled(paramBoolean);
    this.mGpsE.setEnabled(paramBoolean);
  }

  public int[] getLocation()
  {
    int[] arrayOfInt = new int[2];
    arrayOfInt[0] = this.mFootprint.mLatitude;
    arrayOfInt[1] = this.mFootprint.mLongitude;
    return arrayOfInt;
  }

  void initView()
  {
    addView((ViewGroup)((LayoutInflater)getContext().getSystemService("layout_inflater")).inflate(2130903056, null));
    this.mDegN = ((EditText)findViewById(2131492940));
    this.mMinN = ((EditText)findViewById(2131492941));
    this.mSecN1 = ((EditText)findViewById(2131492942));
    this.mSecN2 = ((EditText)findViewById(2131492943));
    this.mDegE = ((EditText)findViewById(2131492945));
    this.mMinE = ((EditText)findViewById(2131492946));
    this.mSecE1 = ((EditText)findViewById(2131492947));
    this.mSecE2 = ((EditText)findViewById(2131492948));
    this.mGpsN = ((Button)findViewById(2131492944));
    this.mGpsE = ((Button)findViewById(2131492949));
    this.mGpsN.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramView)
      {
        String str = GpsUpdatePanel.this.getResources().getString(2131361803);
        if (GpsUpdatePanel.this.mGpsN.getText().toString().equals(str))
          if (GpsUpdatePanel.this.mFootprint.mLatitude > 0)
          {
            Footprint localFootprint2 = GpsUpdatePanel.this.mFootprint;
            localFootprint2.mLatitude = (-1 * localFootprint2.mLatitude);
          }
        while (true)
        {
          GpsUpdatePanel.this.updateEditData(false);
          if (GpsUpdatePanel.this.mCallback != null)
            GpsUpdatePanel.this.mCallback.onUpdatMap();
          return;
          if (GpsUpdatePanel.this.mFootprint.mLatitude >= 0)
            continue;
          Footprint localFootprint1 = GpsUpdatePanel.this.mFootprint;
          localFootprint1.mLatitude = (-1 * localFootprint1.mLatitude);
        }
      }
    });
    this.mGpsE.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramView)
      {
        String str = GpsUpdatePanel.this.getResources().getString(2131361804);
        if (GpsUpdatePanel.this.mGpsE.getText().toString().equals(str))
          if (GpsUpdatePanel.this.mFootprint.mLongitude > 0)
          {
            Footprint localFootprint2 = GpsUpdatePanel.this.mFootprint;
            localFootprint2.mLongitude = (-1 * localFootprint2.mLongitude);
          }
        while (true)
        {
          GpsUpdatePanel.this.updateEditData(false);
          if (GpsUpdatePanel.this.mCallback != null)
            GpsUpdatePanel.this.mCallback.onUpdatMap();
          return;
          if (GpsUpdatePanel.this.mFootprint.mLongitude >= 0)
            continue;
          Footprint localFootprint1 = GpsUpdatePanel.this.mFootprint;
          localFootprint1.mLongitude = (-1 * localFootprint1.mLongitude);
        }
      }
    });
    reset();
    this.updateButton = ((ImageView)findViewById(2131492965));
    this.updateButton.setOnClickListener(this.doUpdate);
    setTextWatcher();
  }

  public boolean isUpdateRequired()
  {
    return this.updateRequired;
  }

  public void removeTextWatcher()
  {
    this.mDegN.removeTextChangedListener(this.textWatcher);
    this.mMinN.removeTextChangedListener(this.textWatcher);
    this.mSecN1.removeTextChangedListener(this.textWatcher);
    this.mSecN2.removeTextChangedListener(this.textWatcher);
    this.mDegE.removeTextChangedListener(this.textWatcher);
    this.mMinE.removeTextChangedListener(this.textWatcher);
    this.mSecE1.removeTextChangedListener(this.textWatcher);
    this.mSecE2.removeTextChangedListener(this.textWatcher);
  }

  public void setData(Footprint paramFootprint)
  {
    this.mFootprint = paramFootprint;
    updateEditData(true);
    Log.i("GpsUpdatePanel", "mFootptint = " + this.mFootprint);
  }

  public void setGpsState(boolean paramBoolean)
  {
    this.gpsEnabled = paramBoolean;
    if (this.gpsEnabled)
      this.updateButton.setOnClickListener(this.doUpdate);
    while (true)
    {
      return;
      this.updateButton.setOnClickListener(this.showAlert);
      this.updateRequired = false;
    }
  }

  public void setTrackingButtonClickable(boolean paramBoolean)
  {
    this.updateButton.setEnabled(paramBoolean);
    switchEditable(paramBoolean);
  }

  public void setTrackingCallback(PanelCallback paramPanelCallback)
  {
    this.mCallback = paramPanelCallback;
  }

  public void setUpdateRequired(boolean paramBoolean)
  {
    this.updateRequired = paramBoolean;
  }

  public void updateEditData(boolean paramBoolean)
  {
    this.isIgnoreEditChange = paramBoolean;
    this.updateButton.requestFocus();
    checkLatitudeLongitude();
    double d1 = this.mFootprint.mLatitude / 1000000.0D;
    double d2 = this.mFootprint.mLongitude / 1000000.0D;
    Log.i("GpsUpdatePanel", "mFootprint.mLatitude = " + this.mFootprint.mLatitude);
    Log.i("GpsUpdatePanel", "mFootprint.mLongitude = " + this.mFootprint.mLongitude);
    if (d1 < 0.0D)
      d1 *= -1.0D;
    if (d2 < 0.0D)
      d2 *= -1.0D;
    String str1 = Location.convert(d1, 2);
    String str2 = Location.convert(d2, 2);
    Log.i("GpsUpdatePanel", "Location.convert, latStr = " + str1);
    Log.i("GpsUpdatePanel", "Location.convert, lonStr = " + str2);
    String[] arrayOfString1 = str1.split(":");
    this.mDegN.setText(arrayOfString1[0]);
    this.mMinN.setText(arrayOfString1[1]);
    String[] arrayOfString2 = arrayOfString1[2].split("\\.");
    this.mSecN1.setText(arrayOfString2[0]);
    String[] arrayOfString4;
    if (arrayOfString2.length >= 2)
    {
      if (arrayOfString2[1].length() > 2)
      {
        String str4 = arrayOfString2[1].substring(0, 2);
        this.mSecN2.setText(str4);
      }
    }
    else
    {
      String[] arrayOfString3 = str2.split(":");
      this.mDegE.setText(arrayOfString3[0]);
      this.mMinE.setText(arrayOfString3[1]);
      arrayOfString4 = arrayOfString3[2].split("\\.");
      this.mSecE1.setText(arrayOfString4[0]);
      if (arrayOfString4.length >= 2)
      {
        if (arrayOfString4[1].length() <= 2)
          break label414;
        String str3 = arrayOfString4[1].substring(0, 2);
        this.mSecE2.setText(str3);
      }
    }
    while (true)
    {
      this.isIgnoreEditChange = false;
      return;
      this.mSecN2.setText(arrayOfString2[1]);
      break;
      label414: this.mSecE2.setText(arrayOfString4[1]);
    }
  }

  public void updateLocationFromEdit(boolean paramBoolean)
  {
    Log.i("GpsUpdatePanel", "updateLocationFromEdit");
    if (this.mFootprint == null);
    while (true)
    {
      return;
      if (paramBoolean)
      {
        if (!this.mHandler.hasMessages(10))
          continue;
        this.mHandler.removeMessages(10);
        checkEditText();
      }
      String str1 = this.mDegN.getText().toString() + ":" + this.mMinN.getText().toString() + ":" + this.mSecN1.getText().toString() + "." + this.mSecN2.getText().toString();
      String str2 = this.mDegE.getText().toString() + ":" + this.mMinE.getText().toString() + ":" + this.mSecE1.getText().toString() + "." + this.mSecE2.getText().toString();
      Log.v("GpsUpdatePanel", "strLat = " + str1);
      Log.v("GpsUpdatePanel", "strLon = " + str2);
      try
      {
        double d1 = Location.convert(str1);
        double d2 = Location.convert(str2);
        Log.v("GpsUpdatePanel", "convert double lat = " + d1);
        Log.v("GpsUpdatePanel", "convert double lon = " + d2);
        this.mFootprint.mLatitude = (int)(1000000.0D * d1);
        this.mFootprint.mLongitude = (int)(1000000.0D * d2);
        String str3 = getResources().getString(2131361805);
        String str4 = getResources().getString(2131361806);
        if ((this.mGpsN.getText().toString().equals(str3)) && (this.mFootprint.mLatitude > 0))
        {
          Footprint localFootprint2 = this.mFootprint;
          localFootprint2.mLatitude = (-1 * localFootprint2.mLatitude);
        }
        if ((this.mGpsE.getText().toString().equals(str4)) && (this.mFootprint.mLongitude > 0))
        {
          Footprint localFootprint1 = this.mFootprint;
          localFootprint1.mLongitude = (-1 * localFootprint1.mLongitude);
        }
        this.mFootprint.mAccuracy = 2;
        Log.i("GpsUpdatePanel", "latitude from edit = " + this.mFootprint.mLatitude);
        Log.i("GpsUpdatePanel", "longitude from edit = " + this.mFootprint.mLongitude);
      }
      catch (IllegalArgumentException localIllegalArgumentException)
      {
        Log.e("GpsUpdatePanel", "Location.convert fail");
        Log.e("GpsUpdatePanel", localIllegalArgumentException.getMessage());
      }
    }
  }

  public static abstract interface PanelCallback
  {
    public abstract void onTracking();

    public abstract void onUpdatMap();
  }
}

/* Location:           E:\workspace\dex2java\dex-translator-0.0.9.3\HtcFootprints_dex2jar.jar
 * Qualified Name:     com.htc.android.footprints.view.GpsUpdatePanel
 * JD-Core Version:    0.6.0
 */